package old;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TimeDateValidator {
	
		public boolean ValidateDate(final String Date) {
			SimpleDateFormat sdf = new SimpleDateFormat("ddMMyy");
		    Date testDate = null;
		    System.out.println("Validate Date fn "+Date);
		    
		    try {
		    	testDate = sdf.parse(Date);
		    }
		    catch (ParseException e) {
		    	System.out.println(Date);
		    	System.out.println("the date you provided is in an invalid date format.");
		    	return false;
		    }
		    if (!sdf.format(testDate).equals(Date)) {
		    	System.out.println("the date you provided is invalid.");
		    	return false;
		    }
		    else {
		    	System.out.println("the date you provided is OKAY.");
		    	return true;
		    }
		}
		
		//this part for validating time
		private Pattern pattern;
		private Matcher matcher;

		private static final String TIME24HOURS_PATTERN = "([01]?[0-9]|2[0-3])[0-5][0-9]";

		public TimeDateValidator(){
		    
		}
		
		/**
		 * Validate time in 24 hours format with regular expression
		 * @param time time address for validation
		 * @return true valid time fromat, false invalid time format
		 */
		public boolean ValidateTime(final String time){
			pattern = Pattern.compile(TIME24HOURS_PATTERN);
			matcher = pattern.matcher(time);
		    return matcher.matches();
		}
}
